package com.iot08.common.entity.app;

import com.iot08.common.utils.StringUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.beans.Transient;
import java.io.Serializable;
import java.util.Date;
import java.util.Map;

/**
 * @version 1.0
 * @Description: 账号实体类
 * @time: 2020/9/1 11:46
 * @author: Rock
 */
@Slf4j
@Data
@Document("account")
public class Account implements Serializable {
    private static final long serialVersionUID = 1L;

    @Field("_id")
    private String id;


    // 上一次的登录类型
    private String old_mobile_type = "";
    // 推送标识
    private String registrationID = "";

    private String oldRegistrationID = "";

    // 关注公众号获取到的微信openid
    private String vipcn_openid;
    // 公众号是否订阅
    private Integer subscribe = 0;
    // 设置公众号模板消息开关状态
    private Integer wechat_send_status = 0;
    // 是否是微信账号
    private Integer wx_status = 0;
    // 手机账号 1
    private Integer account_status = 1;

    private String name;

    private String image;

    // APP登录获取到的微信openid
    private String wxid;

    @Field("wx_name")
    private String wxName;

    @Field("wxgz_ident")
    private Integer wxgzIdent;

    private String unionid;

    private String qqid;

    @Field("qq_name")
    private String qqName;

    private String appleid;

    private String appleName;

    private String phone;

    private String email;

    @Field("phone_m")
    private String phoneM;

    @Field("P")
    private String pwd;

    private String sex;

    @Field("country_code")
    private Integer countryCode;

    private String imei;

    @Field("d")
    private Map<String, Map<String, Object>> deviceMap;

    @Field("g")
    private Map<String, Map<String, Object>> chatGroupMap;

    private String channel;

    private String version;

    //APP的登录类型 iOS 或 安卓
    @Field("mobile_type")
    private String mobileType = "";

    @Field("forbidden_status")
    private String forbiddenStatus = "0";

    @Field("t")
    private Double timestamp;

    private Double deleteNotificationtime; // 标记用户清除系统通知的时间

    private Double deletemsgtime; //标记用户清除提醒消息的时间

    private Integer badge;
    @Field("a")
    private String accesstoken;
    @Field("at")
    private Double accesstokenTime;

    private Boolean letMeAlone;

    @Field("wxgz_chat_imei")
    private String wxgzChatImei;

    @Field("wxgz_masterId")
    private String wxgzMasterId;

    @Field("register_date")
    private Date registerDate;

    @Field("login_date")
    private Date loginDate;

    // 登录类型 platform + channel
    @Field("login_type")
    private String loginType;

    private Date recentlyTime;

//    private Map<String, Object> uuids;

    @Field("delete_cost_time")
    private Double deleteCostTime;

    // APP的包名
    private String packageName;

    // 跟踪信息 再每次打开APP时会记录更新一下 (查询用户关联设备的接口)
    private String trackingInfo;

    /**
     * 是否是imei 号账号
     *
     * @time: 2020/11/12 15:15
     * @author: Rock
     * @version 1.0
     */
    @Transient
    public boolean isImeiAccount() {
        if (StringUtil.isBlank(this.qqid) || StringUtil.isBlank(this.wxid)
                || StringUtil.isBlank(this.unionid) || StringUtil.isBlank(this.wxgzIdent)) {
            return false;
        } else if (StringUtil.isNotBlank(this.imei) && this.imei.length() > 0) {
            return true;
        } else {
            log.error("判断有误,不知是什么账号,");
            return false;
        }
    }
}
